/**
 * Information class for the persons
 */
package ModelLayer;
import java.util.ArrayList;
public class Person
{
    private long id;
    private String name;
    private String address;
    private String postalCode;
    private String city;
    private String phone;
    private ArrayList<Loan> loans;
    
    /**
     * Constructor for objects of class Person
     */
    public Person(long id, String name, String address, String postalCode, String city, String phone)
    {
        this.id = id;
        this.name = name;
        this.address = address;
        this.postalCode = postalCode;
        this.city = city;
        this.phone = phone;
        loans = new ArrayList<>();
        
    }
    
    /**
     * This will set the ID for the person.
     */
    public void setId(long inId)
    {
        id = inId;
    }
    
    /**
     * This will set the name for the person.
     */
    public void setName(String inName)
    {
        name = inName;
    }
    
    /**
     * This will set the address for the person.
     */
    public void setAddress(String inAddress)
    {
        address = inAddress;
    }
    
    /**
     * This will set the postal code for the person.
     */
    public void setPostalCode(String inPostalCode)
    {
        postalCode = inPostalCode;
    }
    
    /**
     * This will set the city for the person.
     */
    public void setCity(String inCity)
    {
        city = inCity;
    }
    
    /**
     * This will set the phone number for the person.
     */
    public void setPhone(String inPhone)
    {
        phone = inPhone;
    }
    
    /**
     * This will return the ID of a person.
     */
    public long getId()
    {
        return id;
    }
    
    /**
     * This will return the name of a person.
     */
    public String getName()
    {
        return name;
    }
    
    /**
     * This will return the address of a person.
     */
    public String getAddress()
    {
        return address;
    }
    
    /**
     * This will return the postal code of a person.
     */
    public String getPostalCode()
    {
        return postalCode;
    }
    
    /**
     * This will return the city of a person.
     */
    public String getCity()
    {
        return city;
    }
    
    /**
     * This will return the phone number of a person.
     */
    public String getPhone()
    {
        return phone;
    }
    
    /**
     * This will print out the information about a person.
     */
    public void printOut()
    {
        System.out.println("ID:\t\t\t\t" + id);
        System.out.println("Name:\t\t\t\t" + name);
        System.out.println("Address:\t\t\t" + address);
        System.out.println("\t\t\t\t" + postalCode);
        System.out.println("\t\t\t\t" + city);
        System.out.println("Telephone number:\t\t" + phone);
        printLoans();
        
    }
    
    /**
     * This will register a loan of a copy on a person.
     */
    public Loan makeLoan(int loanId, String borrowDate, String period, Copy copy)
    {
        Loan loan = new Loan(loanId, borrowDate, period, copy);
        loans.add(loan);
        return loan;
    }
    
    /**
     * This will delete the loan that is registered on a person.
     */
    public void removeLoan(int loanId)
    {
        int i = 0;
        while(i < loans.size())
        {
            if (loans.get(i).getId() == loanId)
            {
                loans.remove(i);
                break;
            }
        }
    }
    
    /**
     * This method prints data of all loans of a preson.
     */
    private void printLoans()
    {
        System.out.println("\nAll loans of a person:\n");
        for(Loan loan: loans)
        {
            loan.printOut();
        }
    }
    
}

